/*//////////////////////////////////////////////////////////
 /// Demo of MVC implementation in javascript UI layer /////
 /// author - Alex Li //////////////////////////////////////
 //////////////////////////////////////////////////////////*/

/**
 ** Demo data - Product
 **/
var ProductsData = [
  [1,"Year Book",10.5,5,"Book"],
  [2,"ActiveX T-Shirt",55,23,"Cloth"],
  [3,"ActiveX Hat",14,15,"Cloth"],
  [4,"LDP Training",120,30,"Training"],
  [5,"GOF Patterns",9.2,2,"Book"],
  [6,"Moon Cake",2,50,"Food"],
  [7,"Anniversary Ticket",0,35,"Misc"],
  [8,"Lucky Gift",10.05,12,"Misc"],
  [9,"Hallowmas T-Shirt",0,5,"Cloth"]
]

/**
 ** Demo data - Customer
 **/
var CustomersData = [
  [1,"Alex Li", "M", "A", 20.5],
  [2,"Neil Yuan","M","A",-10.2],
  [3,"Christing Cao", "F", "B", 5.00],
  [4,"Tian Tian", "F", "C", 12.00],
  [5,"Howey Zhang","M", "B", -32],
  [7,"Ian Ju","M", "A",32.00],
  [8,"Galler Leep","F", "D",40.00],
  [9,"Ian Miller","M", "A",52.00]
]

/////////////////Add more data here to enjoy the game...//////////////////////////

/**
 ** Model object for demo data
 **/
var DemoModel = Class.create();
DemoModel.prototype = Class.extend({
  /**
   ** Load data into model
   **/
  Load:function(request){
    this.data = request.data;
    this.RecordNumber = this.data.length;
    this.NotifyObserver("post_load_data",request);
  },
  
  /**
   ** Delete data from model
   **/
  DeleteById:function(id){
    var context = new Object();
    for(i=0;i<this.data.length;i++){
      if(id==this.Get(i,"id")) {
        context.deletingItem = this.GetRow(i); 
        this.RecordNumber--;
        break;
      } 
    }
    for(j=i;j<this.data.length;j++){
      if(j+1<this.data.length){
        this.data[j] = this.data[j+1];
      } else {
        this.data[j] = null;      
      }
    }
    this.NotifyObserver("delete_record",context);
  }
},Model.prototype);
/////////////////Add more models here to enjoy the game...//////////////////////////


